<?php

if (!defined('BASEPATH')) die('Access Denied.');

/**
 * µMVC Framework (c) 2011.
 * 
 * PHP5 MVC Framework software for PHP 5.2.17 or later
 * 
 * @package         µMVC
 * @filename        system/helpers/form.helper.php
 * @copyright       Lanz (c) 2011.
 * 
 */
/**
 * Form Helper Functions
 * 
 * @package         µMVC
 * @subpackage      Helper
 * @category        System
 * 
 */

if (!function_exists('setValue'))
{

    /**
     * This function helps you to auto fill a form based on the 
     * previous $_POST values. Just specify the same name as the input field
     * name and the field will update automatically.
     * 
     * 
     * @param string $varName specify the same name as the resulting $_POST value
     * @param mixed $default optional default value to be used if no $_POST key exists.
     * @return string either the post value or the default value will be returned.
     */
    function setValue($field, $default = '')
    {      
        $input = \System\Core\Input::instance();
        if (!is_null($input->post($field, NULL)))
        {
            return $input->post($field);
        }

        return $default;
    }

}

if (!function_exists('setSelect'))
{
    
    function setSelect($field, $value, $default)
    {
        
        $input = \System\Core\Input::instance();
        
        $post = $input->post($field, NULL) !== NULL ? $input->post($field) : $default;
        
        if ($value == $post)
        {
            return ' selected="selected"';
        }
        
        return '';
    }
    
}

?>
